# Maintainer: Felix Yan <felixonmars@archlinux.org>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - remove makedepends on python-pypandoc

pkgname=python-voluptuous
pkgver=0.12.1
pkgrel=1
pkgdesc="A Python data validation library"
url="https://github.com/alecthomas/voluptuous"
license=('BSD')
arch=('any')
depends=('python')
makedepends=('python-setuptools')
checkdepends=('python-nose')
source=("https://pypi.io/packages/source/v/voluptuous/voluptuous-$pkgver.tar.gz")
sha512sums=('14ead6bd99c9238318e7ed39fa543cb3363cbb0716a251061e6f533b8fae3fd5e754bd6b2756b6d76745da0e02236e04bfe0ae4e25dd87d291bb2a716660eebc')

prepare() {
  # https://github.com/alecthomas/voluptuous/issues/333
  rm -r voluptuous-$pkgver/*.egg-info

  # https://github.com/alecthomas/voluptuous/pull/332
  sed -e "s/'w'/'wb'/" -e "s/.encode('utf-8')//" -e "s/f.write(long_description)/f.write(long_description.encode('utf-8'))/" -i voluptuous-$pkgver/setup.py

  # Python 3.7
  sed -i '/raise StopIteration/d' voluptuous-$pkgver/voluptuous/schema_builder.py
}

build() {
  cd voluptuous-$pkgver
  python setup.py build
}

check() {
  cd voluptuous-$pkgver
  python setup.py nosetests
}

package() {
  cd voluptuous-$pkgver
  python setup.py install --root="$pkgdir" --optimize=1
  install -Dm644 COPYING "$pkgdir"/usr/share/licenses/$pkgname/COPYING
}
